
import Vue from "vue";
import Vuex from "vuex";

import * as api from '@/api/getmusic'


Vue.use(Vuex)
// 将创建出的vuex实例对象导出
export default new Vuex.Store({
    state: {
        // 定义正在播放的歌单中所有的歌曲
        songsList: [{
            al: {
                id:120954841,
                name: "告五人",
                pic: 109951165585701060,
                picUrl:"https://p1.music.126.net/5URIeP6GjMFg_hKhGloNTA==/109951165585701063.jpg"
            },
            id: 1807799505,
            
            name:"唯一",
            ar:[{
                name: "告五人",
            }]
           
        }],
        // 定义播放的是哪一首歌曲
        whichSong: 0,

        // 定义播放状态
        flag: false,

        // 歌曲播放的时间
        currentTime: 0,

        // 储存歌词的变量
        songLyric: '',

        // 播放模式
        XplayingModel:false,

        
       
        

    },
    actions: {
        // 获取歌词
        GET_SONG_LYRIC(context, payload) {
            api.getMusicLyric(payload)
                .then(res => {
                    // console.log(res);
                    context.commit('GOT_SONG_LYRIC', res.data.lrc.lyric)
                })
        },

        // 获取歌单id，根据歌单id请求数据
        GET_SONGS_DATA(context,payload){
            api.getSongs(payload)
            .then(res => {
                context.commit('GOT_SONGS_DATA',res.data.songs)
            })
        }
    },
    mutations: {
        GETSONGSDATA(state, payload) {
            state.songsList = payload
            // console.log(state.songsList);
        },


        // 播放样式的开关
        CHANGEPLAYBTN(state, payload) {
            state.flag = !payload
            // console.log(state.flag);
        },
        CHANGESONGSLIST(state, payload) {
            state.songsList = payload
        },

        CHOOSEWHICH(state, payload) {
            state.whichSong = payload
            // console.log(state.whichSong);
        },

        GOT_PLAYING_TIMES(state, payload) {
            state.currentTime = payload
            // console.log(state.currentTime);
        },

        // 得到歌词 
        GOT_SONG_LYRIC(state, payload) {
            state.songLyric = payload
            // console.log(state.songLyric);
        },

        // 改变播放模式
        CHANGE_MODEL(state){
            state.XplayingModel = !state.XplayingModel
            // console.log(state.XplayingModel);
        },


        // 得到新的所有的歌曲
        GOT_SONGS_DATA(state,payload){
            state.songsList = payload
            // console.log(state.songsList);
        },

        // 获得播放器
        GOT_MUSIC_AUDIO(state,payload){
            state.Audio = payload
            // console.log(state.Audio);
        },

        // 暂停播放器
        STOP_MUSIC_AUDIO(state,payload){
            state.Audio.pause()
            // console.log(1);
        },

        // 切换歌单时
        CHANGE_INDEX(state){
            state.whichSong = ''
        }
    },
    modules: {

    }
})